package com.gewu.bookeeping.Utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

import androidx.appcompat.app.AlertDialog;

import com.gewu.bookeeping.R;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class AppCot {

    public static String name;
    public static Bitmap bitmap;

    /**
     * 个人中心页面列表
     *
     * @return
     */
    public static List<String> fourList() {
        List<String> lists = new ArrayList<>();
        lists.add("账户分析");
        lists.add("关于开发者");
        lists.add("设置");
        lists.add("退出账户");
        return lists;
    }

    /**
     * 保存微信权限
     *
     * @param context
     * @param f
     */
    public static void savewecahrt(Context context, boolean f) {
        SharedPreferences preferences = context.getSharedPreferences("w", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("is", f);
        editor.apply();
    }

    /**
     * 获取微信权限
     *
     * @param context
     * @param
     */
    public static boolean getwechart(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("w", Context.MODE_PRIVATE);
        boolean is = preferences.getBoolean("is", false);
        return is;
    }

    /**
     * 支付包
     *
     * @param context
     * @param f
     */
    public static void saveali(Context context, boolean f) {
        SharedPreferences preferences = context.getSharedPreferences("a", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("is", f);
        editor.apply();
    }

    /**
     * 支付宝
     *
     * @param context
     * @return
     */
    public static boolean getali(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("a", Context.MODE_PRIVATE);
        boolean is = preferences.getBoolean("is", true);
        return is;
    }

    /**
     * 支付包
     *
     * @param context
     * @param f
     */
    public static void isok(Context context, boolean f) {
        SharedPreferences preferences = context.getSharedPreferences("a", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("is", f);
        editor.apply();
    }

    /**
     * 支付宝
     *
     * @param context
     * @return
     */
    public static boolean isno(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("a", Context.MODE_PRIVATE);
        boolean is = preferences.getBoolean("is", false);
        return is;
    }

    /**
     * 短信
     */
    public static void savemes(Context context, boolean f) {
        SharedPreferences preferences = context.getSharedPreferences("m", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("is", f);
        editor.apply();
    }

    /**
     * 短信
     */
    public static boolean getmes(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("m", Context.MODE_PRIVATE);
        boolean is = preferences.getBoolean("is", false);
        return is;
    }

    /**
     * 保存微信权限
     */
    public static AlertDialog.Builder showDilog(Activity context, String name, String content) {
        AlertDialog.Builder alertDialog1 = new AlertDialog.Builder(context);
        alertDialog1.setTitle(name);
        alertDialog1.setMessage(content);//内容
        alertDialog1.setIcon(R.mipmap.one_ic);//图标
        alertDialog1.create();
        return alertDialog1;
    }

    /**
     * 获取通知权限 本机
     *
     * @param activity
     * @return
     */
    public static boolean isEnabled(Activity activity) {
        String pkgName = activity.getPackageName();
        final String flat = Settings.Secure.getString(activity.getContentResolver(), "enabled_notification_listeners");
        if (!TextUtils.isEmpty(flat)) {
            final String[] names = flat.split(":");
            for (int i = 0; i < names.length; i++) {
                final ComponentName cn = ComponentName.unflattenFromString(names[i]);
                if (cn != null) {
                    if (TextUtils.equals(pkgName, cn.getPackageName())) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    /**
     * 获取系统时间
     *
     * @return
     */
    public static String getTime() {
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // HH 24小时格式 ; hh 12小时格式
        Date date = new Date(System.currentTimeMillis());
        String format = simpleDateFormat.format(date);
        return format;
    }


    /**
     * 最强日志
     *
     * @param bug
     */
    public static void supreLog(String bug) {
        Log.i("TAG", "onCreate: " + "" +
                "\n★□■□■□■□■□■□■□■ □■□■□■□■□■□■□★\n" +
                "☆∴.﹡﹒＊﹒。．☆....﹒。．∴＊'．﹒..∴☆．.﹒. ﹒..∴☆\n" +
                "┌═╮◆╭═┐╭═┐╭═┐╭═┐╭═┐╭═┐ ╭═┐◆╭═┐\n" +
                "║┌╯◆║ ║║ ║ +" + bug + "║!!!║◆╰┐║\n" +
                "╰╯↘◆└═╯└═╯└═╯└═╯└═╯└═╯ └═╯◆↙╰╯\n" +
                "☆∴.﹡﹒＊﹒。．☆...﹒。．∴.＊'．﹒..∴☆．.﹒. ﹒..∴☆\n" +
                "★□■□■□■□■□■□■□■ □■□■□■□■□■□■□★");
    }

    /**
     * 最强日志
     */
    public static void ssuprLog() {
        Log.i("TAG", "ssuprLog: " + "" +
                "\n☆★☆★☆★☆★☆★☆★☆★☆★☆\n" +
                "★　　│　心想　│　事成　│　　★\n" +
                "☆灌╭═╮　　╭═╮　　╭═╮灌☆\n" +
                "★水│人│　　│口│　　│幸│水★\n" +
                "☆　│氣│　　│水│　　│福│　☆\n" +
                "★　│超│　　│多│　　│滿│　★\n" +
                "☆灌│旺│　　│多│　　│滿│灌☆\n" +
                "★水│㊣│　　│㊣│　　│㊣│水★\n" +
                "☆　╰═╯天天╰═╯開心╰═╯　☆\n" +
                "★☆★☆★☆★☆★☆★☆★☆★☆★.\n" +
                "If you love me, just hold me\n");
    }


    /**
     * 获取当前时间
     *
     * @param date
     * @return
     */
    public static String getDate(Date date) {
        @SuppressLint("SimpleDateFormat")
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = format.format(date);
        return str;
    }

    /**
     * 截取字符串
     *
     * @param notificationText
     * @return
     */
    public static String getText(String notificationText) {
        if (notificationText.contains(":")) {
            String str1 = notificationText.substring(0, notificationText.indexOf(":"));
            String str2 = notificationText.substring(str1.length() + 1, notificationText.length());
            return str2;
        } else {
            return notificationText;
        }
    }


    /**
     * 短信截取字符串
     *
     * @param notificationText
     * @return
     */
    public static String getText2(String notificationText) {
        if (notificationText.contains("您")) {
            String str1 = notificationText.substring(0, notificationText.indexOf("您"));
            String str2 = notificationText.substring(str1.length(), notificationText.length());
            return str2;
        } else {
            return notificationText;
        }

    }

    /**
     * 截取金额
     * 截取特定字符之间的数据
     *
     * @param str
     * @return
     */
    public static String getMoney(String str) {
        //如下的方法一样
        if (str.contains("款") && str.contains("元")) {
            int index = str.indexOf("款");
            int index1 = str.indexOf("元");
            String substring = str.substring(index + 1, index1);
            return substring;
        } else {
            return "0";
        }
    }


    /**
     * 截取金额
     * 短信截取特定字符之间的数据
     *
     * @param str
     * @return
     */
    public static String getMoney2(String str) {
//        如果此条消息不包含 这两个字  就反悔一个0；
        if (str.contains("额") && str.contains("元")) {
            int index = str.indexOf("额");
            int index1 = str.indexOf("元");
            String substring = str.substring(index + 1, index1);
            return substring;
        } else {
            return "0";
        }

    }


}
